/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.wpi.first.wpilibj.templates.commands;

import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;

/**
 *
 * @author Robotics
 */
public class EncodedShooter extends CommandBase {
    
    private double encoderLimit = 0;
    private boolean firstTime;
    private boolean isDone;
    
    public EncodedShooter() {
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);
        requires(catapult);
    }

    // Called just before this Command runs the first time
    protected void initialize(){
        encoderLimit = SmartDashboard.getNumber("Catapult Encoder Limit: ", 0);
        firstTime = true;
        isDone = false;
    }

    // Called repeatedly when this Command is scheduled to run
    protected void execute(){
        if(firstTime){
            catapult.startMotors();
            firstTime = false;
        }
        if(catapult.getCatapultEncoderValue() >= encoderLimit){
            catapult.stopMotors();
            catapult.setMotorSpeeds(-1.0 / 10.0);
        }
        if(catapult.getCatapultEncoderValue() <= 0.0){
            catapult.stopMotors();
            isDone = true;
        }
        catapult.updateEncoders();
    }

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        return isDone;
    }

    // Called once after isFinished returns true
    protected void end(){
    }

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
    }
}
